home *** CD-ROM | disk | FTP | other *** search
- ; ROUTINES FOR CHAPTER 7 - GRAPHICS - ADVANCED FUNCTIONS
- ;
- ; For 320 x 200 color graphics mode
- ;
- extrn setpt:far,xorpt:far,locate:far
- extrn setbox:far,xorbox:far
- extrn x0:word,y0:word,x1:word,y1:word,x2:word,y2:word
- extrn color:word
- extrn ptable:word
- ;
- ;*********************************************************
- stacks segment stack
- db 100 dup('paint stack ')
- paintstack label word
- db 100 dup('regular stack ')
- stacks ends
- ;*********************************************************
- datas segment public
- ;
- public font
- public xmagn,ymagn
- public xmess,ymess
- ;
- ; public parameters
- font db 0
- xmagn db 1
- ymagn db 1
- xmess dw ?
- ymess dw ?
- ;
- ; parameters needed for line drawing routine
- dels dw ?
- delp dw ?
- dele dw ?
- ;
- deltas label word
- delsx dw ?
- delsy dw ?
- delse dw ?
- deldx dw ?
- deldy dw ?
- delde dw ?
- ;
- datas ends
- ;**********************************************************
- video segment at 0B800h
- video ends
- ;**********************************************************
- ex4adv segment
- ;
- public gmessout
- public setline
- public schar,rchar
- public paint
- ;
- assume cs:ex4adv,ds:datas,es:video,ss:stacks
- ;
- ;----------------------- routine begins ------------------------------+
- ; ROUTINE TO DRAW LINE
- ;
- setline proc far
- push bx ; save registers
- push cx
- push dx
- push si
- push di
- push ax
- ;
- ; set up x and y updates
- mov si,1 ; start with positive 1 for x update
- mov di,1 ; start with positive 1 for y updats
- ;
- ; find |y2-y1|
- mov dx,y2 ; get y2
- sub dx,y1 ; subtract y1
- jge storey ; skip if y2-y1 is nonegative
- neg di ; move in negative y direction
- neg dx ; absolute value of y2-y1
- storey:
- mov deldy,di ; store y update for diagonal moves
- ;
- ; find |x2-x1|
- mov cx,x2 ; get x2
- sub cx,x1 ; subtract x1
- jge storex ; skip if x2-x1 is nonnegative
- neg si ; move in negative x direction
- neg cx ; absolute value of x2-x1
- storex:
- mov deldx,si ; store x update for diagonal moves
- ;
- ; sort |y2-y1| and |x2-x1|
- cmp cx,dx ; compare dels with delp
- jge setdiag ; skip if straight moves in x direction
- mov si,0 ; if straight=vertical: kill x update
- xchg cx,dx ; and exchange differences
- jmp storedelsxy
- ;
- setdiag:
- mov di,0 ; if straight=horizontal: kill y update
- ; store dels, delp, delsx, and delsy
- storedelsxy:
- mov dels,cx ; change in straight direction
- mov delp,dx ; change in perpendicular to straight
- mov delsx,si ; x update in straight direction
- mov delsy,di ; y update in straight direction
- ;
- ; get initial values for x and y
- mov si,x1 ; x-coordinate
- mov di,y1 ; y-coordinate
- ;
- ; compute initial value and increments for error function
- mov ax,delp
- sal ax,1 ; 2*delp
- mov delse,ax ; change if straight move
- ;
- sub ax,cx ; 2*delp - dels
- mov bx,ax ; initial value
- ;
- sub ax,cx ; 2*delp - 2*dels
- mov delde,ax ; change if diagonal move
- ;
- ; adjust count
- inc cx
- ;
- ; set the color
- mov dx,color ; get the color
- ;
- ; main loop structure
- lineloop:
- call setpt ; plot the point
- cmp bx,0 ; determine straight or diagonal move
- jge diagonal
- ;
- ; case for straight move
- straight:
- add si,delsx ; update x
- add di,delsy ; update y
- add bx,delse ; update error term
- loop lineloop ; next point
- jmp lineexit
- ;
- ; case for diagonal move
- diagonal:
- add si,deldx ; update x
- add di,deldy ; update y
- add bx,delde ; update error term
- loop lineloop ; next point
- ;
- lineexit:
- pop ax ; restore registers
- pop di
- pop si
- pop dx
- pop cx
- pop bx
- ret
- ;
- setline endp
- ;----------------------- routine ends --------------------------------+
- ex4adv ends ; end of code segment
- ;
- end